<?php
require_once ("conf.php");
require_once ("lib/Snoopy.class.php");
require_once ("lib/func.php");

$snoopy = new Snoopy();

//$snoopy->proxy_host = "http://127.0.0.1:8888";

$products_count = getApiUrl("/admin/products/count.json");
$snoopy->fetch($products_count);
$rs   = $snoopy->results;
$data = json_decode($rs,true);

$count = $data['count'];

$pages =  ceil($count / SHOPIFY_PAGE_SIZE );
for($p=1; $p<=$pages; $p++){
    $products_json = getApiUrl("/admin/products.json?page=" . $p);

    $snoopy->fetch($products_json);
    $product_rs   = $snoopy->results;
    file_put_contents("p-".$p.".txt",$product_rs);
    $product_data = json_decode($product_rs,true);

    foreach($product_data['products'] as $d){
        addProducts($d);
    }
}

